<?php if (!defined('BASIC_PATH')) exit; ?>
<?php require('header.php'); ?>
<div class="p-3 mb-4 bg-light rounded-3">
    <div class="container-fluid">

        <form class="upload-form">
            <div class="fade">
                <input type="radio" class="btn-check upload-type" name="type" value="1" id="btnradio-file"
                       autocomplete="off" checked>
                <input type="radio" class="btn-check upload-type" name="type" value="2" id="btnradio-text"
                       autocomplete="off">
            </div>
            <nav>
                <div class="nav nav-tabs btn-group mb-4" id="nav-tab" role="tablist" style="display: inline-flex">
                    <label class="btn btn-outline-primary fs-2 active" for="btnradio-file" id="nav-file-tab"
                           data-bs-toggle="tab" data-bs-target="#nav-file" type="button" role="tab"
                           aria-controls="nav-file" aria-selected="true">上传文件</label>
                    <label class="btn btn-outline-primary fs-2" for="btnradio-text" id="nav-text-tab"
                           data-bs-toggle="tab" data-bs-target="#nav-text" type="button" role="tab"
                           aria-controls="nav-text" aria-selected="false">分享文字</label>
                </div>
            </nav>
            <div class="tab-content upload-box" id="nav-tabContent">
                <div class="dropzone mb-4 tab-pane fade show active" id="nav-file" role="tabpanel"
                     aria-labelledby="nav-file-tab"></div>
                <div class="mb-4 tab-pane fade" id="nav-text" role="tabpanel" aria-labelledby="nav-text-tab">
                    <textarea class="wordtext" name="text" cols="30" rows="10" placeholder="请输入文字，5000字以内"
                              autocomplete="off"></textarea>
                </div>
            </div>
            <div class="return-box g-3 mb-4" style="display: none">
                <div class="row justify-content-center my-4">
                    <div class="col col-12 text-center mb-1"><h5 class="text-secondary">扫码即可下载/浏览，或使用提取码/链接提取</h5>
                    </div>
                    <div class="col col-auto qrcode-box">
                        <!--生成二维码-->
                    </div>
                    <div class="col-auto text-success">
                        <!--文件下载信息-->
                    </div>
                </div>
            </div>
            <div class="row g-3 mb-4 option-box">
                <div class="form-floating col-sm-8">
                    <input type="text" class="form-control" id="desc" placeholder="备注">
                    <label for="desc">备注信息</label>
                </div>
                <div class="form-floating col-sm">
                    <input type="number" class="form-control" id="exp" placeholder="过期时间(小时)" value="24">
                    <label for="exp">过期时间(小时, 0为永不过期)</label>
                </div>
                <div class="form-floating col-sm" style="display: none">
                    <input type="number" class="form-control" id="times" placeholder="下载次数" value="5">
                    <label for="times">下载次数</label>
                </div>
                <div class="form-floating col-sm-2" style="display: none">
                    <input type="text" class="form-control" id="password" placeholder="下载密码" value="">
                    <label for="password">下载密码</label>
                </div>
            </div>
            <div class="progress wb-progress mb-4" style="height: auto">
                <span class="btn btn-lg progress-bar progress-bar-striped progress-bar-animated" type="button"
                      style="width: 100%;display: none;">1%</span>
                <button class="btn btn-primary btn-lg saveForm" type="button" style="width: 100%">提 交</button>
            </div>
            <input type="file" multiple="multiple" class="dz-hidden-input"
                   style="visibility: hidden; position: absolute; top: 0px; left: 0px; height: 0px; width: 0px;">
        </form>
        <!--div class="alert alert-info" role="alert">
            文件过期获取超过下载次数后，系统将自动清理文件。使用下载密码时需要下载地址和密码都对应上才能正常下载。
        </div-->

    </div>
</div>
<div class="row align-items-md-stretch">
    <?php if(C('password')!== false): ?>
    <div class="col-md-6">
        <div class="h-100 p-3 bg-light border rounded-3 container">
            <h6 class="border-bottom py-2">已上传文件</h6>
            <div class="row justify-content-around uploads-box overflow-scroll" style="max-height: 130px">
                <?php foreach (get_all_jsons(20) as $file): ?>
                    <a href="index.php?sid=<?php echo $file['sid']; ?>" target="_blank" type="button"
                       class="btn btn-secondary position-relative my-2 col-5" title="SID:<?php echo $file['sid']; ?>">
                        <?php
                        if ($file['type'] == 2) {
                            echo '<div class="text-truncate" style="max-width: 100%">' . substr(trim(str_replace(array("/r/n", "/r", "/n", "\r\n", "\r", "\n"), '', $file['wordtext'])), 0, 50) . '</div>';
                        } else {
                            echo '<div class="text-truncate" style="max-width: 100%">';
                            $file_name = [];
                            foreach ($file['files'] as $f) {
                                $file_name[] = $f['name'];
                            }
                            echo implode(',', $file_name);
                            echo '</div>';
                        }
                        ?>
                        <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-<?php echo $file['type'] == 2 ? 'primary' : 'success'; ?>">
                                <?php echo $file['type'] == 2 ? '文本' : '文件 ' . count($file['files']); ?>
                            </span>
                    </a>
                <?php endforeach; ?>
            </div>

        </div>
    </div>
    <div class="col-md-6">
        <?php require('info-list.php'); ?>
    </div>
    <?php else: ?>
    <div class="col-md-12">
        <?php require('info-list.php'); ?>
    </div>
    <?php endif; ?>

</div>
<script src="assets/main.js?v=<?php echo time(); ?>"></script>
<?php require('footer.php'); ?>
